package com.hmall.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.common.PageDTO;
import com.hmall.item.mapper.ItemMapper;
import com.hmall.item.Item;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
public class ItemService extends ServiceImpl<ItemMapper, Item> implements IItemService {

    @Autowired(required = false)
    private ItemMapper itemMapper;


    /**
     * 扣减库存
     * @param num
     * @param itemId
     */
    @Transactional //事务
    @Override
    public void subItemStock(Integer num, Long itemId) {
        itemMapper.subItemStock(num,itemId);
        System.err.println("库存已经扣减!");
    }

    /**
     * 增加库存
     * @param num
     * @param itemId
     */
    @Transactional //事务
    @Override
    public void recoverItemStock(Integer num, Long itemId) {
        itemMapper.recoverItemStock(num,itemId);
        System.err.println("库存数据已回滚!");
    }
}
